package com.huatai.bpmn.controller;

import com.alibaba.fastjson.JSONObject;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.huatai.bpmn.entity.TbRiskEntity;
import com.huatai.bpmn.service.TbRiskService;
import com.huatai.common.api.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: nzj
 * @Description:
 * @DateTime: 2023/8/21 15:46
 **/
@RestController
@RequestMapping("/risk")
@Api(value = "风险控制", tags = "风险控制")
public class RiskController {
	@Autowired
	private TbRiskService riskService;


	/**
	 * 添加或更新风险类型
	 * @param tbRiskEntity
	 * @return
	 */
	@PostMapping("addOrUpdateRisk")
	@ApiOperationSupport(includeParameters = {
		"tbRiskEntity.id",
		"tbRiskEntity.riskType",
		"tbRiskEntity.msg",
		"tbRiskEntity.querySql"
	})
	@ApiOperation(value = "添加或更新风险类型", notes = "添加或更新风险类型")
	public R addOrUpdateRisk(@RequestBody TbRiskEntity tbRiskEntity){
		return riskService.addOrUpdateRisk(tbRiskEntity);
	}

	/**
	 * 获取风险清册
	 */
	@PostMapping("findRiskList")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "page", value = "页码", dataType = "Integer"),
		@ApiImplicitParam(name = "limit", value = "条数", dataType = "Integer"),
	})
	@ApiOperation(value = "获取风险清册", notes = "获取风险清册")
	public R findRiskList(@RequestBody JSONObject jsonObject){
		return riskService.findRiskList(jsonObject);
	}

	/**
	 * 根据id删除风险类型
	 */
	@GetMapping("removeRiskById")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "id", value = "风控id", dataType = "Integer"),
	})
	@ApiOperation(value = "根据id删除风险类型", notes = "根据id删除风险类型")
	public R removeRiskById(@RequestParam Long id){
		return riskService.removeById(id)?R.data("删除成功！"):R.fail("删除失败！");
	}

	/**
	 * 风控监测
	 * @param jsonObject
	 * @return
	 */
	@PostMapping("riskCheck")
	@ApiOperation(value = "风控监测逆向校验，如果sql查询有结果就不通过,没有结果则通过校验", notes = "风控监测逆向校验，如果sql查询有结果就不通过,没有结果则通过校验")
	public R riskCheck(@RequestBody JSONObject jsonObject){
		return riskService.riskCheck(jsonObject);
	}

}
